; Inno Setup script for Demigod mod
; Instructions for use:
; 1. Download and install Inno Setup: http://www.jrsoftware.org/isdl.php
; 2. Edit this file by searching for the ***** comments and following the instructions.
; 3. Click the compile button above.
; 4. Make sure you test!

[Setup]

; ***** The Name of your mod
AppName=Bman's Godlike Team Panel
; ***** The Name of your mod including version number
AppVerName=Bman's Godlike Team Panel v1.2.2
; ***** You are the publisher right?
AppPublisher=bman654
; ***** Version number that will be embedded in the setup.exe
VersionInfoVersion=1.2.2
; Looks for the DG install folder
DefaultDirName={reg:HKLM\Software\Stardock\Drengin.net\Demigod,Path|{pf}\Demigod}
DirExistsWarning=no
EnableDirDoesntExistWarning=yes
DisableProgramGroupPage=true
Uninstallable=no
; ***** Where do you want Inno Setup to put the setup file?
OutputDir=.
; ***** What do you want to call the setup.exe file? (do NOT put the .exe on the end)
OutputBaseFilename=bman_godlike_teampanel_1.2.2_setup

[Files]
; ***** For SOURCE, point to where your mod files are located.  For DESTDIR, it will put it in the DG\bindata\mods folder.  You just need to put the foldername your mod will exist in within the mods folder.
; The EXCLUDES line included in this example will exclude .SVN folders (subversion junk), ~ files (GVIM junk), .ISS files (INNOSETUP script files), .EXE files (your setup file!).  Add any other file patterns you want to exclude
Source: .\src\*; DestDir: {app}\bindata\mods\Bman Godlike Team Panel; Excludes: ".svn,*~,*.iss,*.exe,*.zip"; Flags: ignoreversion overwritereadonly replacesameversion recursesubdirs

[Code]
var DGNotFoundWarned: Boolean;
function InitializeSetup(): Boolean;
begin
  DGNotFoundWarned := False;
  Result := True;
end;

{ See if this folder looks like the Demigod folder }
function IsValidDGFolder(const Folder: String): Boolean;
begin
  Result := FileExists(RemoveBackslashUnlessRoot(Folder) + '\bin\demigod.exe');
end;

{ Do not show the select dir page if we found the Demigod folder. }
function ShouldSkipPage(PageID: Integer): Boolean;
  var DGPath : String;
begin
  case PageID of
    wpSelectDir:
      begin
        Result := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Stardock\Drengin.net\Demigod', 'Path', DGPath);
        If Result Then
          Result := IsValidDGFolder(DGPath);

        If Not Result Then
        begin
          If Not DGNotFoundWarned Then
          begin
            DGNotFoundWarned := True;
            MsgBox('Could not find your Demigod installation.  Please select the main Demigod folder', mbInformation, MB_OK);
          end;
        end;
      end;
  else
    Result := False;
  end;
end;

{ Make sure the folder the user selected is correct! }
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  case CurPageID of
    wpSelectDir:
      begin
        Result := IsValidDGFolder(ExpandConstant('{app}'));
        If Not Result Then
          MsgBox('The folder you selected does not look like the main Demigod folder.  Please select the main Demigod folder', mbInformation, MB_OK);
      end;
  else
    Result := True;
  end;
end;

{ Remind the user to enable the mod from within the game. }
procedure CurStepChanged(CurStep: TSetupStep);
begin
  case CurStep of
    ssPostInstall:
      MsgBox('Remember to enable the mod from within the game using the Mod Manager menu!', mbInformation, MB_OK);
  end;
end;
